<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

   $country = DEFAULT_COUNTRY_VALUE; 
  if (!isset($process)) $process = false;
?>


  <div>
    <span class="inputRequirement" style="float: right;"><?php echo FORM_REQUIRED_INFORMATION; ?></span>
    <h2><?php echo NEW_ADDRESS_TITLE; ?></h2>
  </div>

  <div class="contentText">
<script type="text/javascript">
	$(document).ready(function(){
		$("select[name=zone_id]").change(function(){
			  $("select[name=city_id]").html('<option value="0"><?php echo ENTRY_CITY_LOADIND; ?> </option>');
			  $.post("<?php echo FILENAME_CITY_PROCESS; ?>",
			         {zone_id:$(this).val()},
			          function(valor){
			          	  $("select[name=city_id]").html(valor);
			          	}
			         )
			})
	})
</script>
	 <table border="0" width="100%" cellspacing="2" cellpadding="2">

<?php
  if (ACCOUNT_GENDER == 'true') {
    $male = $female = false;
    if (isset($gender)) {
      $male = ($gender == 'm') ? true : false;
      $female = !$male;
    } elseif (isset($entry['entry_gender'])) {
      $male = ($entry['entry_gender'] == 'm') ? true : false;
      $female = !$male;
    }
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_GENDER; ?></td>
        <td class="fieldValue"><?php echo tep_draw_radio_field('gender', 'm', $male) . '&nbsp;&nbsp;' . MALE . '&nbsp;&nbsp;' . tep_draw_radio_field('gender', 'f', $female) . '&nbsp;&nbsp;' . FEMALE . '&nbsp;' . (tep_not_null(ENTRY_GENDER_TEXT) ? '<span class="inputRequirement">' . ENTRY_GENDER_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  }
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_FIRST_NAME; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('firstname', (isset($entry['entry_firstname']) ? $entry['entry_firstname'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_FIRST_NAME_TEXT) ? '<span class="inputRequirement">' . ENTRY_FIRST_NAME_TEXT . '</span>': ''); ?></td>
      </tr>
      <tr>
        <td class="fieldKey"><?php echo ENTRY_LAST_NAME; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('lastname', (isset($entry['entry_lastname']) ? $entry['entry_lastname'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_LAST_NAME_TEXT) ? '<span class="inputRequirement">' . ENTRY_LAST_NAME_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  if (ACCOUNT_COMPANY == 'true') {
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_COMPANY; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('company', (isset($entry['entry_company']) ? $entry['entry_company'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_COMPANY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COMPANY_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  }
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_STREET_ADDRESS; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('street_address', (isset($entry['entry_street_address']) ? $entry['entry_street_address'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_STREET_ADDRESS_TEXT) ? '<span class="inputRequirement">' . ENTRY_STREET_ADDRESS_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  if (ACCOUNT_SUBURB == 'true') {
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_SUBURB; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('suburb', (isset($entry['entry_suburb']) ? $entry['entry_suburb'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_SUBURB_TEXT) ? '<span class="inputRequirement">' . ENTRY_SUBURB_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  }
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_POST_CODE; ?></td>
        <td class="fieldValue"><?php echo tep_draw_input_field('postcode', (isset($entry['entry_postcode']) ? $entry['entry_postcode'] : '')) . '&nbsp;' . (tep_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="inputRequirement">' . ENTRY_POST_CODE_TEXT . '</span>': ''); ?></td>
      </tr>

<?php
  if (ACCOUNT_STATE == 'true') {
  		 $check_query = tep_db_query("select entry_zone_id, entry_city from " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$HTTP_GET_VARS['edit'] . "' and customers_id = '" . (int)$customer_id . "' limit 1");
       $check = tep_db_fetch_array($check_query);
  		 $zone_id = $check['entry_zone_id'];
  		 $city_name = $check['entry_city'];

       echo '<br>'. $city_id .'</br>';

?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_STATE; ?></td>
        <td class="fieldValue">
  		  <select name="zone_id">
  		 <?php
  		 
      if (isset($zone_id)) {
        $zqy1 = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '".(int)$country."' and zone_id = '". (int)$zone_id ."' order by zone_name asc");
        $zv1 = tep_db_fetch_array($zqy1);
        echo '<option value="' . $zv1['zone_id'] . '">' . $zv1['zone_name'] . '</option>';
        echo '<option value="0">'. ENTRY_STATE_CHOOSE .'</option>';
        $zqy = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '".(int)$country."' and zone_id <> '". (int)$zone_id ."' order by zone_name asc");
        while ($zv = tep_db_fetch_array($zqy)) {
           echo '<option value="' . $zv['zone_id'] . '">' . $zv['zone_name'] . '</option>';
         }
      } else {
        echo '<option value="0">'. ENTRY_STATE_CHOOSE .'</option>';
        $zqy = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '".(int)$country."' order by zone_name asc");
        while ($zv = tep_db_fetch_array($zqy)) {
          echo '<option value="' . $zv['zone_id'] . '">' . $zv['zone_name'] . '</option>';
        }
      }
  		 
        ?>
  	    </select><?php echo '&nbsp;<span class="inputRequirement">' . ENTRY_STATE_TEXT . '</span>'?>
       	</td>
      </tr>

<?php
  }
?>

      <tr>
        <td class="fieldKey"><?php echo ENTRY_CITY; ?></td>
        <td class="fieldValue">
  	  <select name="city_id">
  		 <option value="0" disabled="disabled"><?php echo ENTRY_CITY_CHOOSE; ?></option>
  		 <?php
      if (isset($city_name)) {
        $cqy = tep_db_query("select city_id, city_name from " . TABLE_CITIES . " where city_zone_id = '" . $zone_id . "' and city_name = '". $city_name ."' order by city_name asc");
        $ct = tep_db_fetch_array($cqy);
        echo '<option value="' . $ct['city_id'] . '">' . $ct['city_name'] . '</option>';
        echo '<option value="0">'. ENTRY_STATE_CHOOSE .'</option>';
      } else {
        echo '<option value="0" disabled="disabled"><'. ENTRY_CITY_CHOOSE .'</option>';
      }
      ?>
  	  </select><?php echo '&nbsp;<span class="inputRequirement">' . ENTRY_CITY_TEXT . '</span>'?>
    	  </td>
      </tr>
      <tr>
        <td class="fieldKey"><?php echo ENTRY_COUNTRY; ?></td>
        <td class="fieldValue"><?php echo DEFAULT_COUNTRY; $country = DEFAULT_COUNTRY_VALUE; ?></td>
      </tr>

<?php
  if ((isset($HTTP_GET_VARS['edit']) && ($customer_default_address_id != $HTTP_GET_VARS['edit'])) || (isset($HTTP_GET_VARS['edit']) == false) ) {
?>

      <tr>
        <td class="fieldValue" colspan="2"><?php echo tep_draw_checkbox_field('primary', 'on', false, 'id="primary"') . ' ' . SET_AS_PRIMARY; ?></td>
      </tr>

<?php
  }
?>
    </table>
  </div>
